<template>
  <van-picker
    title="标题"
    show-toolbar
    :columns="columns"
    :default-index="value"
    @confirm="onConfirm"
    @cancel="$emit('close')"
  />
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  components: {},
  props: {
    value: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      columns: ['男', '女'],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async onConfirm(value, index) {
      // console.log(index)
      this.$toast.loading({
        message: '保存中',
        forbidClick: true,
        duration: 0,
      })
      try {
        await updateUserProfile({
          gender: index,
        })
        this.$emit('close')
        this.$emit('input', value)
        this.$toast.success('更新成功')
      } catch (err) {
        this.$toast.fail('更新失败')
      }
    },
  },
}
</script>

<style lang="less" scoped></style>
